#include "fig_vars.h"
#include "fig_constants.h"
#include "build.h"

#include "application/game_rms.h"

#ifdef _PLATFORM_IOS
#include <sys/types.h>
#include <sys/sysctl.h>

#endif


FIGVars::FIGVars() : GameRMS(),
m_DeviceType(DEVICE_TYPE_UNKNOWN)
{
	
 /*

#ifdef _PLATFORM_IOS
    // https://developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man3/sysctlbyname.3.html
    int mib[2];
    size_t len;
    char *p;
    
    mib[0] = CTL_HW;
    mib[1] = HW_MACHINE;
    sysctl(mib, 2, NULL, &len, NULL, 0);
    p = new char(len);
    sysctl(mib, 2, p, &len, NULL, 0);
    
    char	        DeviceName[]   =
    {
        (p[0]),
        (p[1]),
        (p[2]), 
        '\0'
    };
    
    if (strcmp(DeviceName, "iph")==0)
    {
        // iphone
        m_DeviceType = DEVICE_TYPE_IPHONE;
    }
    else if(strcmp(DeviceName, "ipo")==0)
    {
        // ipod
        m_DeviceType = DEVICE_TYPE_IPOD;
    }
    else if(strcmp(DeviceName, "ipa")==0)
    {
        // ipad
        m_DeviceType = DEVICE_TYPE_IPAD;
    }
    else
    {
        m_DeviceType = DEVICE_TYPE_SIMULATOR;
        // simulator
    }
    
	delete p;
    
#endif
 
*/
	
    
}




void	FIGVars::ResetCustom()
{
    
#if defined(_PLATFORM_IOS) || defined( _PLATFORM_ANDROID)
    GameRMS::Instance()->SetCanTilt(true);
	//GameRMS::Instance()->SetCanVibrate(IsVibrationAvilable());
#endif
    
	if(!GetProfile())
	{
#ifdef _BUILD_CHINESE
		AddProfile("Neo","Chinese","ac");	
#else
		AddProfile("Neo","English","ac");	
#endif

	}
    
	if(GameRMS::Instance()->GetCanTilt())
        GameRMS::Instance()->SetEnableTilt(true);
    
    if(GameRMS::Instance()->GetCanVibrate())
        GameRMS::Instance()->SetEnableVibrate(true);
    
    
}


void	FIGVars::FIGReset()
{
	SetInt((int)VAR_NAMES_BOMB_COUNT, FIGConstants::NUCLEAR_NEWGIVEN_COUNT);
	SetInt((int)VAR_NAMES_PLAYERCRAFT_REMAIN, FIGConstants::PLAYER_NEWGIVEN_COUNT);

#ifndef _PLATFORM_IOS
#ifdef NDEBUG 
	SetInt((int)VAR_NAMES_IS_FULL_VERSION, 1);
#endif
#endif
    
#ifdef PRO_VERSION
    SetInt((int)VAR_NAMES_IS_FULL_VERSION, 1);
#endif


}

/*

bool	FIGVars::IsVibrationAvilable() const
{
	
	if( m_DeviceType == FIGVars::DEVICE_TYPE_IPHONE ||
       m_DeviceType  == FIGVars::DEVICE_TYPE_IPAD)
		return true;
    
	return false;
}
 */

int		FIGVars::GetCurrentLevel()
{
	int Difficulty = GetInt(VAR_NAMES_DIFFICULTY);
    
	FIGVars::VAR_NAMES VarType;
	switch(Difficulty)
	{
	case 0:
		VarType =   VAR_NAMES_CURRENT_LEVEL_EASY;
		break;

	case 1:
		VarType =   VAR_NAMES_CURRENT_LEVEL_NORMAL;
		break;

	case 2:
		VarType =   VAR_NAMES_CURRENT_LEVEL_HARD;
		break;
	
	};

	return	GetInt(VarType);

}
	
int		FIGVars::GetMaxPlayableLevel()
{
	//SetInt((int)VAR_NAMES_MAX_PLAYABLE_LEVEL_NORMAL, FIGConstants::LEVEL_LAST);
	//SetInt((int)VAR_NAMES_MAX_PLAYABLE_LEVEL_EASY, FIGConstants::LEVEL_LAST);
	//SetInt((int)VAR_NAMES_MAX_PLAYABLE_LEVEL_HARD, FIGConstants::LEVEL_LAST);

	int Difficulty = GetInt(VAR_NAMES_DIFFICULTY);
    
	FIGVars::VAR_NAMES VarType;
	switch(Difficulty)
	{
	case 0:
		VarType =   VAR_NAMES_MAX_PLAYABLE_LEVEL_EASY;
		break;

	case 1:
		VarType =   VAR_NAMES_MAX_PLAYABLE_LEVEL_NORMAL;
		break;

	case 2:
		VarType =   VAR_NAMES_MAX_PLAYABLE_LEVEL_HARD;
		break;
	
	};

	return	GetInt(VarType);
}

void		FIGVars::SetCurrentLevel(int LevelNum)
{
	int Difficulty = GetInt(VAR_NAMES_DIFFICULTY);
    
	FIGVars::VAR_NAMES VarType;
	switch(Difficulty)
	{
	case 0:
		VarType =   VAR_NAMES_CURRENT_LEVEL_EASY;
		break;

	case 1:
		VarType =   VAR_NAMES_CURRENT_LEVEL_NORMAL;
		break;

	case 2:
		VarType =   VAR_NAMES_CURRENT_LEVEL_HARD;
		break;
	
	};

	SetInt(VarType,LevelNum);
}

void		FIGVars::SetMaxPlayableLevel(int LevelNum)
{
	int Difficulty = GetInt(VAR_NAMES_DIFFICULTY);
    
	FIGVars::VAR_NAMES VarType;
	switch(Difficulty)
	{
	case 0:
		VarType =   VAR_NAMES_MAX_PLAYABLE_LEVEL_EASY;
		break;

	case 1:
		VarType =   VAR_NAMES_MAX_PLAYABLE_LEVEL_NORMAL;
		break;

	case 2:
		VarType =   VAR_NAMES_MAX_PLAYABLE_LEVEL_HARD;
		break;
	
	};

	SetInt(VarType,LevelNum);
}


